package com.Algorithm.HUAWEI.one20211020;


import java.util.Map;
import java.util.Scanner;
import java.util.TreeMap;

/**
 * Created with IntelliJ IDEA.
 *
 * @Author: zjz
 * @Date: 2022/02/27/11:49
 * @Description:
 * @Target:
 */
public class 合并表记录 {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int i1 = Integer.valueOf(in.nextLine());
        TreeMap<Integer,Integer> treeMap = new TreeMap();
        for (int i = 0; i < i1; i++) {
            String[] ss = in.nextLine().split(" ");
            if (treeMap.containsKey(Integer.valueOf(ss[0]))){
                treeMap.put(Integer.valueOf(ss[0]),(treeMap.get(Integer.valueOf(ss[0]))+Integer.valueOf(ss[1])));
            }else {
                treeMap.put(Integer.valueOf(ss[0]),Integer.valueOf(ss[1]));
            }

        }

        for (Map.Entry<Integer, Integer> o: treeMap.entrySet()){
            System.out.println(o.getKey() + " " + o.getValue());
        }


    }
}
